using Api.Model;
using Api.Dal;
using System.Collections.Generic;

namespace Api.Bll
{
    public class MessageBll
    {
        public int count { get; set; }
        
        // 获取用户的所有私信
        public List<Message> GetMessages(int userId)
        {
            return MessageDAL.GetMessages(userId);
        }

        // 拉黑用户
        public bool BlockUser(int userId, int blockedUserId)
        {
            return MessageDAL.BlockUser(userId, blockedUserId);
        }

        // 解除拉黑
        public bool UnblockUser(int userId, int blockedUserId)
        {
            return MessageDAL.UnblockUser(userId, blockedUserId);
        }

        // 判断用户是否被拉黑
        public bool IsUserBlocked(int userId, int blockedUserId)
        {
            return MessageDAL.IsUserBlocked(userId, blockedUserId);
        }

        // 获取两个用户之间的所有私信，展示
        public List<Message> GetMessagesBetweenUsers(int userId1, int userId2)
        {
            return MessageDAL.GetMessagesBetweenUsers(userId1, userId2);
        }

        // 获取两个用户之间的所有私信，并标记为已读状态
        public List<Message> GetMessagesBetweenUsersAndMarkAsRead(int userId1, int othersId2)
        {
            return MessageDAL.GetMessagesBetweenUsersAndMarkAsRead(userId1, othersId2);
        }
        

        // 获取未读私信
        public List<IGrouping<int, Message>> GetAllUnreadMessagesGroupedBySender(int userId)
        {
            return MessageDAL.GetAllUnreadMessagesGroupedBySender(userId);
        }

        // 发送私信
        public int? SendMessage(int senderId, int receiverId, string text)
        {
            return MessageDAL.SendMessage(senderId, receiverId, text);
        }

        // 撤回私信
        public bool RevokeMessage(int messageId, int userId)
        {
            return MessageDAL.RevokeMessage(messageId, userId);
        }

        // 标记私信为已读
        public bool MarkMessageAsRead(int messageId)
        {
            return MessageDAL.MarkMessageAsRead(messageId);
        }

        // 删除私信
        public bool DeleteMessage(int messageId)
        {
            return MessageDAL.DeleteMessage(messageId);
        }

        // 删除用户之间的所有私信
        public bool DeleteMessagesBetweenUsers(int userId, int otherUserId)
        {
            return MessageDAL.DeleteMessagesBetweenUsers(userId, otherUserId);
        }

        // 根据Id获取单条私信
        public Message GetMessagesById(int MessageId)
        {
            return MessageDAL.GetMessageById(MessageId);
        }
    }
}
